package com.itheima.web.job;

import com.itheima.service.db.UserInfoService;
import com.itheima.web.manager.UserManager;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Component
public class MyFreezeJob {
    @Autowired
    StringRedisTemplate redisTemplate;


   @Reference
    UserInfoService userInfoService;
    @Scheduled(cron = "0 0/1 * * * ?")
    public void status(){
        Set<String> keys = redisTemplate.keys("user*");
        List<String>list1=new ArrayList<>();
        for (String key:keys){
           list1.add(key);

        }
        List<Long>list2=userInfoService.findStatus();
        List<String>user=new ArrayList<>();
        for (Long list3:list2){

            user.add("user"+list3);
        }
        user.removeAll(list1);

        for (String us:user){
            String[]strArray = us.split( "r" );
            String ids=strArray[1];
            Integer id = Integer.parseInt(ids);
            userInfoService.findUserupdate(id);
            System.out.println("完成操作");
        }




    }
}
